{% extends "base.html" %}

{% block content %}
<h4>Loading log: {{ file }}...</h4>
<div id="container">

    <div id="log">
        <pre id="{{ file }}" ></pre>
    </div>
</div>
{% endblock %}
{% block footer %}{{ super() }}{% endblock %}
{% block js %}
{{ super() }}
<script>
    const output = document.getElementById('{{ file }}');

    const xhr = new XMLHttpRequest();
    {% if mode == 'tail' or mode == 'full' %}
        xhr.open('GET', '/logreader?logfile={{ file }}&mode=full&json=1');
    {% else %}
        xhr.open('GET', '/logreader?logfile={{ file }}&mode={{ mode }}&json=1');
    {% endif %}
    xhr.open
    xhr.send();

    setInterval(function() {
        output.textContent = xhr.responseText;
        {% if mode == 'tail' %}
            window.scrollTo(0, document.querySelector("#content").scrollHeight);
        {% endif %}
    }, 1000);

</script>
{% endblock %}

